<?xml version="1.0" encoding=""?>
<!DOCTYPE html PUBLIC "-//Tigris//DTD XHTML 1.0 Transitional//EN" "http://style.tigris.org/tigris_transitional.dtd">
<html>
<head>
  <meta http-equiv="content-type" content=""/>
  <title>Siconos call</title>
  <style type="text/css">
/* <![CDATA[ */ 
@import "css/readyset.css"; 
@import "css/inst.css";
/*  ]]>
 */
 </style>
  <link rel="stylesheet" type="text/css" href="css/print.css" media="print"/>
</head>

<body>

The goal of this document is to give a global view of the timestepping implementation in SICONOS.

<h1>Global Stack</h1>
<ul>
	<li>Model::initialize
	<ul>
		<li>Topology::initialize</li>
		<span style="padding-left:20px"><font size="-1">calculate relative degrees and number of index sets</font></span>
		<li>Simulation::initalize</li>
		<ul>
			<li>EventManager::initialize</li>
			<span style="padding-left:20px"><font size="-1">e.g. save data</font></span>
			<li>DynamicSystem::initialize</li>
			<li>OneStepIntegrator::initialize</li>
			<li>TimeStepping::initLevelMax</li>
			<span style="padding-left:20px"><font size="-1">define number of index sets by Simulation strategy and relative degree of UnitaryRelation</font></span>
			<li>Topology::indexSetsResize</li>
			<span style="padding-left:20px"><font size="-1">resizes vector of UnitaryRelationsGraph to include graphs of active UnitaryRelation in specific updateIndexSet method</font></span>			
			<li>Timestepping::initOSNS</li>
			<span style="padding-left:20px"><font size="-1">initialize position depending index sets and OSNS</font></span>
		</ul>
	</ul>
	<li>TimeStepping::computeOneStep -> TimeStepping::advanceToEvent -> TimeStepping::NewtonSolve</li>
	<li>TimeStepping::nextStep</li>
</ul>
  
<h2>TimeStepping::newtonSolve</h2>
<ul>  
  	<li>TimeStepping::computeInitialResidu</li>
  	<li>CASE : LINEAR</li>
  	<ul>
  		<li>TimeStepping::prepareNewtonIteration</li>
     	<li>TimeStepping::computeFreeState</li>
     	<li>TimeStepping::computeOneStepNSProblem(SICONOS_OSNSP_TimeStepping_VELOCITY)</li>
     	<li>TimeStepping::(Default)CheckSolverOutput</li>
     	<li>TimeStepping::update</li>
     	<li>TimeStepping::saveYandLambdaInMemory</li>
  	</ul>
  	<li>CASE : NONLINEAR -> LOOP WITH INDIVIDUAL STEP :</li>
  	<ul>
  		<li>TimeStepping::prepareNewtonIteration</li>
     	<li>TimeStepping::computeFreeState</li>
     	<li>TimeStepping::computeOneStepNSProblem(SICONOS_OSNSP_TimeStepping_VELOCITY)</li>
     	<li>TimeStepping::(Default)CheckSolverOutput</li>
     	<li>TimeStepping::update</li>
     	<li><strong>TimeStepping:newtonCheckConvergence</strong></li>
     	<li>TimeStepping::saveYandLambdaInMemory</li>
  	</ul>
</ul>
    
<h3>TimeStepping::computeInitialResidu</h3>
<ul>
	<li>Relation::computeh <em>(virtual)</em> -> Relation::computeOutput</em></li>
	<span style="padding-left:20px"><font size="-1">compute local gaps for all Relations</font></span>
	<li>Relation::computeg <em>(virtual)</em> -> Relation::computeInput</li>
	<span style="padding-left:20px"><font size="-1">compute local forces for all Relations</font></span>
	<li>DynamicalSystem::updatePlugins</li>
	<span style="padding-left:20px"><font size="-1">update plugin functions for the DynamicalSystem graph</font></span>
	<li><font color="#FF0000">OneStepIntegrator</font>::computeResidu <em>(virtual)</em></li>
	<span style="padding-left:20px"><font size="-1">compute the <strong>global free residu</strong> DS->residuFree and the <strong>global residu</strong> DS->workFree for all OneStepIntegrators to cope with nonlinearities in velocity equation</font></span>
	<li>Relation::computeResiduY <em>(virtual)</em></li>
	<span style="padding-left:20px"><font size="-1">compute the <strong>local free residu</strong> for output Relations (gaps) to cope their nonlinearities if switched on</font></span>
</ul>
	    			
<h3>TimeStepping::prepareNewtonIteration</h3>
<ul>
	<li>Moreau::computeW</li>
	<span style="padding-left:20px"><font size="-1">compute the iteration matrix for OneStepIntegrators</font></span>
	<li>Relation::computeJach <em>(virtual)</em></li>
	<span style="padding-left:20px"><font size="-1">compute output Jacobians for all Relations</font></span>
	<li>Relation::computeJacg <em>(virtual)</em></li>
	<span style="padding-left:20px"><font size="-1">compute input Jacobians for all Relations</font></span>
	<li>DynamicalSystem::preparStep</li>
	<span style="padding-left:20px"><font size="-1">prepare the DynamicalSystem graph : only to prepare for external software</font></span>
	<li>Relation::preparNewtonIteration</li>
	<span style="padding-left:20px"><font size="-1">prepare all Relations : only to prepare for external software</font></span>
	<li>OneStepNonsmoothProblem::setHasBeUpdated</li>
	<span style="padding-left:20px"><font size="-1">inform all OneStepNonsmoothProblems about changed topology due to new index sets after Timestepping::nextStep</font></span>
</ul>
	  			
<h3>TimeStepping::computeFreeState</h3>
<span style="padding-left:20px">-> <font color="#FF0000">OneStepIntegrator</font>::computeFreeState <em>(virtual)</em></span><br/>
<span style="padding-left:20px"><font size="-1">compute the global free state for all OneStepIntegrators in connected DynamicalSystems in DS->workFree</font></span>

<h3>Simulation::computeOneStepNSProblem</h3>
<span style="padding-left:20px">-> OneStepNonsmoothProblem::compute <em>(virtual)</em></span><br/>
<span style="padding-left:20px"><font size="-1">solve all OneStepNonsmoothProblems</font></span>	  		
<ul>
	<li>OneStepNonsmoothProblem::preCompute <em>(virtual) -</em></li>
	<span style="padding-left:20px"><font size="-1">calculate input for numerical solution method from local values (cf. Section 'Building of Numerics Matrix')</font></span>
	<li>Solve OneStepNonsmoothProblem</li>
	<span style="padding-left:20px"><font size="-1">interface to numerical solution method</font></span>     				
	<li>OneStepNonsmoothProblem::postCompute <em>(virtual)</em></li>
	<span style="padding-left:20px"><font size="-1">restore local gap and force from numerical solution method output</font></span>
</ul>

<h3>TimeStepping::(Default)CheckSolverOutput</h3>
<span style="padding-left:20px"><font size="-1">reaction on numerical solution method flags</font></span>
			
<h3>TimeStepping::update</h3>
<ul>
	<li>Simulation::updateInput</li>
	<ul>
		<li>OneStepIntegrator::resetNonsmoothPart <em>(virtual)</em></li>
		<span style="padding-left:20px"><font size="-1">set global force to zero for all Interactions</font></span>
	 	<li>Interaction::computeInput -> Relation::computeInput <em>(virtual)</em></li>
		<span style="padding-left:20px"><font size="-1">compute global force from local forces for all Interactions</font></span>
	</ul>
	<li><font color="#FF0000">OneStepIntegrator</font>::updateState <em>(virtual)</em></li>
	<span style="padding-left:20px"><font size="-1">compute new state for all OneStepIntegrators</font></span>
	<li>TimeStepping::updateWorldFromDS</li>
	<span style="padding-left:20px"><font size="-1">update connected software, e.g. CAD, with new state</font></span> 				
	<li>Simulation::updateOutput -> Interaction::computeOutput -> Relation::computeOutput <em>(virtual)</em></li>
	<span style="padding-left:20px"><font size="-1">compute local gaps from global values for all Interactions</font></span> 
</ul>

<h3>TimeStepping::newtonCheckConvergence</h3>
<li><font color="#FF0000">OneStepIntegrator</font>::computeResidu <em>(virtual)</em></li>
<span style="padding-left:20px"><font size="-1">compute the <strong>global free residu</strong> DS->residuFree and the <strong>global residu</strong> DS->workFree for all OneStepIntegrators to cope with nonlinearities in velocity equation</font></span>
<li>Relation::computeResiduY <em>(virtual)</li>
<span style="padding-left:20px"><font size="-1">compute the <strong>local free residu</strong> for output Relations (gaps) to cope their nonlinearities if switched on</font></span>
<li>Relation::computeResiduR <em>(virtual)</em></li>
<span style="padding-left:20px"><font size="-1">compute the <strong>local free residu</strong> for input Relations (forces) to cope their nonlinearities if switched on</font></span>

<h3>TimeStepping::saveYandLambdaInMemory</h3>
<span style="padding-left:20px">-> Interaction::swapInMemory <em>(virtual)</em></span><br/>
<span style="padding-left:20px">-> Interaction::swapTimeStepInMemory <em>(virtual)</em></span><br/>
<span style="padding-left:20px"><font size="-1">save local gap and force for having initial guess and possibility to calculate Jacobians in next Newton step</font></span>

<h3>Building of Numerics Matrix</h3>
<span style="padding-left:20px">-> OneStepNonsmoothProblem::preCompute</span><br/>
<span style="padding-left:20px"><font size="-1">implemented only for LinearOSNS involving LinearOSNS::_M OSNSMatrix, LinearOSNS::_q SiconosVector</font></span>
<ul>
	<li>OneStepNonsmoothProblem::updateUnitaryBlocks</li>
   <ul>
		<li>OneStepNonsmoothProblem::computeDiagUnitaryBlocks</li>
		<li>OneStepNonsmoothProblem::computeUnitaryBlocks</li>
	</ul>
   <li>OSNSMatrix_M::fill(indexset)</li>
   <li>_keepLambdaAndYState if switched on</li>
   <li>LinearOSNS::computeq -> LinearOSNS::computeqBlock -> <font color="#FF0000">OneStepIntegrator</font>::computeFreeOutput</li>
   <span style="padding-left:20px"><font size="-1">not implemented for Moreau2</font></span>
</ul>
    
<h2>TimeStepping::nextStep</h2>
<span style="padding-left:20px">-> Simulation::processEvent -> EventsManager::processEvents -> EventsManager::OptimizedProcessEvent</span><br/>
<ul>
	<li>TimeDiscretizationEvent::process -> Simulation::saveInMemory</li>
	<ul>
		<li>OneStepIntegrator::saveInMemory -> DynamicalSystem::swapInMemory <em>(virtual)</em></li>
	   <span style="padding-left:20px"><font size="-1">save state and set global force to zero <strong>WHY</strong></font></span>
	   <li>OneStepNonsmoothProblem::saveInMemory -> Interaction::swapInMemory <em>(virtual)</em></li>
		<li>OneStepNonsmoothProblem::saveTimeStepInMemory -> Interaction::swapTimeStepInMemory <em>(virtual)</em></li>
		<span style="padding-left:20px"><font size="-1">save local gap and force</font></span>
	</ul>
	<li>Simulation::updateIndexSets</li>
	<span style="padding-left:20px"><font size="-1">only position depending for TimeStepping and Newton loop does not depend on position</font></span>
	<ul>
		<li>TimeStepping::updateIndexSet</li>
	   <li>Topology::indexSet::update_vertices_indices</li>
	   <li>Topology::indexSet::update_edges_indices</li>
   </ul>
	<li>TimeDiscretization::increment</li>
	<li>EventManager::update</li>
</ul>

<h2>TimeSteppingProjectOnConstraints::newtonSolve</h2>
<span style="padding-left:20px"><font size="-1">projection on position only for NewtonEulerDS with kinetic metric</font></span>
<ul>
	<li>TimeSteppingProjectOnConstraints::newtonSolve</li>
	<ul>
    	<li>TimeStepping::computeOneStepNSProblem</li>
    	<li>NewtonEulerDS::normalizeq</li>
    	<li>NewtonEulerDS::updateT</li>
    	<li>TimeStepping::updateWorldFromDS</li>
    	<li>Relation::computeh</li>
		<li>Relation::computeJach</li>
  	</ul>
</ul>

</body>

</html>
